﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Mail;

namespace BLL
{
    public class MailService
    {
        private SmtpClient smtpClient; 

        public MailService(string mailAdress, string password)
        {
            MailAddress personalMaiAdress = new MailAddress(mailAdress);
            smtpClient = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(personalMaiAdress.Address, password)
            };
        }

        public void sendMail(string fromAdress, List<string> recipientAdresses, string subject, string message)
        {
            MailMessage mailMsg = new MailMessage();
            
            
            foreach (string adress in recipientAdresses)
            {
                mailMsg.To.Add(new MailAddress(adress));
            }

            mailMsg.From = new MailAddress(fromAdress);
            mailMsg.Subject = subject;
            mailMsg.Body = message;
            
            smtpClient.Send(mailMsg); 
        }
    }
}
